<form class="layui-form padding-r20" id="add-department-panel">
    <div class="layui-form-item">
        <label class="layui-form-label">名称：</label>
        <div class="layui-input-block">
            <input type="text" model="department_name" required placeholder="请输入部门名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部长：</label>
        <div class="layui-input-block">
            <select model="user_id" id="departmentUserSelect" lay-verify="" lay-search>

            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea model="department_info"  placeholder="请输入简介" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" id="btn-add-department">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use('form', function () {
        var form = layui.form;
        $.post(api.user.getAllName, function (res) {
            data = res.data;
            $("#departmentUserSelect").html('<option value="">请选择部长</option>');
            $.each(data, function (index, Item) {
                var option = '<option value="' + Item["user_id"] + '">' + Item["user_name"] + '</option>';
                $("#departmentUserSelect").append(option);
            });
            form.render();
        },'json');
        form.render();
    });
    $("#btn-add-department").click(function(){
        var data = getModel({elem : '#add-department-panel'});
        var validate = new Validate();
        var check = validate.check(data,[
            ['department_name','require','部门名称'],
            ['user_id','require','部长'],
            ['department_info','require','部门简介']
        ]);
        if(!check){
            msg(validate.getError());
            return false;
        }
        $.post(api.department.addDepartment,data,function(res){
            Log(res);
            if(res.code){
                msg('添加成功');
                reloadTable("departments",api.department.getAllDepartment);
                return true;
            }
            msg(res.msg);
        },'json');
    });
</script>